<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>state</title>
</head>
<body>
    <!--准备好一个“容器”-->
    <div id="test"></div>

    <!--引入react核心库,必须在dom前面引入-->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!--引入react_dom，用于支持react操作DOM-->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!--引入babel，用于将jsx转为js-->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/babel">
        class Weather extends React.Component{
            constructor(props) {
                super(props);
                this.state = {
                    isHot:true
                }
            }
            change1(){
                this.setState({
                    isHot: !this.state.isHot
                })
            }
            change2 = ()=>{
                this.setState({
                    isHot: !this.state.isHot
                })
            }
            render(){
                console.log(this)
                return(
                    // 两种写法，知识箭头函数写在不同的地方
                    <div>
                        <h1 onClick={()=>{this.change1();}}>今天天气很{this.state.isHot ? '炎热' : '寒冷'}</h1>
                        <h1 onClick={this.change2}>今天天气很{this.state.isHot ? '炎热' : '寒冷'}</h1>
                    </div>
                )
            }
        }
        ReactDOM.render(<Weather/>,document.getElementById('test'))
    </script>

</body>
</html>